from django.db import models
# from ckeditor_uploader.fields import RichTextUploadingField
from mdeditor.fields import MDTextField


class Category(models.Model):
    category = models.CharField(max_length=64,verbose_name="类别名称")

    def __str__(self):
        return u'<Category:%s>'%self.category

    class Meta:
        db_table = "t_category"
        verbose_name_plural = u'类别'


class Tag(models.Model):
    tag = models.CharField(max_length=64,verbose_name="标签名称")

    def __str__(self):
        return f'<Tag:{self.tag}>'

    class Meta:
        db_table = "t_tag"
        verbose_name_plural = u'标签'


class Post(models.Model):
    title = models.CharField(max_length=120,verbose_name="标题")
    desc = models.CharField(max_length=240,verbose_name="描述")
    # content = models.TextField(verbose_name="内容")
    # content = RichTextUploadingField(verbose_name="内容")  # 集成富文本编辑器
    content = MDTextField(verbose_name="内容")   # markdown编辑器
    created = models.DateTimeField(auto_now_add=True,verbose_name="创建时间")
    modified = models.DateTimeField(auto_now=True,verbose_name="修改时间")
    isdelete = models.BooleanField(default=False,verbose_name="是否删除")
    category = models.ForeignKey(Category,verbose_name="所属类别",on_delete=models.CASCADE)
    tag = models.ManyToManyField(Tag,verbose_name="所属标签")

    def __str__(self):
        return f'<Post:{self.title}>'

    class Meta:
        db_table = 't_post'
        verbose_name_plural = u'帖子'
